package com.cloudbroker.bcs.platform.dav.middle.bizservice.impl;

import com.cloudbroker.bcs.common.cache.CacheClient;
import com.cloudbroker.bcs.common.cache.redis.RedisClient;
import com.cloudbroker.bcs.common.cache.redis.mybatis.BasicRedisConfig;
import com.cloudbroker.bcs.common.entity.HSBCPSBackVO;
import com.cloudbroker.bcs.common.util.VOUtil;
import com.cloudbroker.bcs.platform.dav.bizapi.service.base.vo.HSBCPSVO;
import com.cloudbroker.bcs.platform.dav.bizapi.service.common.cache.CacheBizService;
import com.cloudbroker.bcs.platform.dav.common.util.CacheHelper;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * Created by xuyn15828 on 2016/6/1.
 */
@Service
public class CacheBizServiceImpl implements CacheBizService {

    @Override
    public HSBCPSBackVO funcClearDBCache(HSBCPSVO param) {
        CacheClient cacheClient = CacheHelper.getInstance().getCacheClient();
        if( cacheClient instanceof RedisClient ) {
            RedisClient redisClient = (RedisClient) cacheClient;
            Set<String> fieldSet = redisClient.hkeys(BasicRedisConfig.CACHE_KEY_NAMESPACE);
            if( null != fieldSet && !fieldSet.isEmpty() ) {
                String[] fieldAry = fieldSet.toArray(new String[fieldSet.size()]);
                redisClient.del(fieldAry);
                redisClient.hdel(BasicRedisConfig.CACHE_KEY_NAMESPACE , fieldAry );
            }
        }
        return VOUtil.genSuccessBackVo();
    }
}
